/***********************************************************************  
 *   @package：cn.wj.base.controller，@class-name：CommonType.java   
 *   @copyright     Copyright:   2015-2016     
 *   @creator       wenjie 
 *   @create-time   2016年3月2日   下午1:03:11   
 *   @revision      $Id: 1.0    
 ***********************************************************************/
package cn.wj.base.controller;

import java.text.ParseException;
import java.text.SimpleDateFormat;

public enum CommonType {
	String() {
		@Override
		public Object getValue(java.lang.String value) {
			return value;
		}

		@Override
		public CommonType setType(Class<?> type) {
			// TODO Auto-generated method stub
			return null;
		}
	},
	Integer() {
		@Override
		public Object getValue(java.lang.String value) {
			if(value==null ||"".equals(value.trim()))return null;
			return java.lang.Integer.parseInt(value.trim());
		}

		@Override
		public CommonType setType(Class<?> type) {
			// TODO Auto-generated method stub
			return null;
		}
	},
	Double() {
		@Override
		public Object getValue(java.lang.String value) {
			if(value==null ||"".equals(value.trim()))return null;
			return java.lang.Double.parseDouble(value.trim());
		}

		@Override
		public CommonType setType(Class<?> type) {
			// TODO Auto-generated method stub
			return null;
		}
	},
	Float() {
		@Override
		public Object getValue(java.lang.String value) {
			if(value==null ||"".equals(value.trim()))return null;
			return java.lang.Float.parseFloat(value.trim());
		}

		@Override
		public CommonType setType(Class<?> type) {
			return null;
		}
	},
	Long() {
		@Override
		public Object getValue(java.lang.String value) {
			if(value==null ||"".equals(value.trim()))return null;
			return java.lang.Long.parseLong(value.trim());
		}

		@Override
		public CommonType setType(Class<?> type) {
			return null;
		}
	},
	Date() {
		@Override
		public Object getValue(java.lang.String value) {
			if(value==null ||"".equals(value))return null;
			SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
			java.util.Date date = null;
			try {
				date = format.parse(value.trim());
			} catch (ParseException e) {
				e.printStackTrace();
			}
			return date;
		}

		@Override
		public CommonType setType(Class<?> type) {
			return null;
		}
	},
	help() {
		@Override
		public Object getValue(java.lang.String value) {
			return null;
		}

		@Override
		public CommonType setType(Class<?> type) {
			if (type == java.lang.String.class) {
				return String;
			} else if (type == java.lang.Integer.class) {
				return Integer;
			} else if (type == java.lang.Float.class) {
				return Float;
			} else if (type == java.lang.Long.class) {
				return Long;
			} else if (type == java.lang.Double.class) {
				return Double;
			}  else if (type == java.util.Date.class) {
				return Date;
			} else {
				return null;
			}
		}
	};
	public abstract Object getValue(java.lang.String value);
	public abstract CommonType setType(Class<?> type);
}
